# -*- mode: python ; coding: utf-8 -*-

import sys
import os
from PyInstaller.utils.hooks import collect_all

# 项目根目录（确保路径正确）
BASE_DIR = os.getcwd()

# 收集数据文件
datas = [
    ('update.py', '.'),
    ('git_sync.py', '.'),
    ('core', 'core'),
    ('utils', 'utils'),
]

# 收集模块依赖
hiddenimports = [
    'update',
    'git_sync',
    'core.state_manager',
    'core.file_operations',
    'core.ui_components',
    'core.system_utils',
    'core.tray_icon',
    'utils.logger',
    'utils.input_dialogs',
    'utils.time_helpers',
    'utils.constants',
]

# 自动收集 PIL 和 tkinter 依赖
for module in ['PIL', 'tkinter']:
    try:
        data, imports = collect_all(module)
        datas.extend(data)
        hiddenimports.extend(imports)
    except Exception as e:
        print(f"Warning: Failed to collect {module} dependencies: {e}")

# 平台相关依赖
hiddenimports += [
    'pystray._win32',
    'pystray._darwin',
    'pystray._xorg',
    'psutil._psutil_windows',
    'psutil._psutil_posix',
]

# 分析入口
a = Analysis(
    ['tracker.py'],
    pathex=[BASE_DIR],
    binaries=[],
    datas=datas,
    hiddenimports=hiddenimports,
    hookspath=[],
    hooksconfig={},
    runtime_hooks=[],
    excludes=[],
    win_no_prefer_redirects=False,
    win_private_assemblies=False,
    cipher=None,
    noarchive=False,
)

# 打包为 EXE
pyz = PYZ(a.pure, a.zipped_data, cipher=None)

exe = EXE(
    pyz,
    a.scripts,
    a.binaries,
    a.zipfiles,
    a.datas,
    [],
    name='Tracker',
    debug=False,
    bootloader_ignore_signals=False,
    strip=False,
    upx=True,
    upx_exclude=[],
    runtime_tmpdir=None,
    #console=False,  
    console=True,  # 控制台窗口
    disable_windowed_traceback=False,
    argv_emulation=False,
    target_arch=None,
    codesign_identity=None,
    entitlements_file=None,
)